package uz.rt.dicom.tag;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;


/** Creates a list of {@link DicomTag} elements. */
public class DicomTagList implements Iterable<DicomTag>
{
// ------------------------------ FIELDS ------------------------------

    private ArrayList<DicomTag> list = null;

// --------------------------- CONSTRUCTORS ---------------------------

    public DicomTagList()
    {
        list = new ArrayList<DicomTag>();
    }

    public DicomTagList(int size)
    {
        list = new ArrayList<DicomTag>(size);
    }

    public DicomTagList(final Collection<? extends DicomTag> c)
    {
        list = new ArrayList<DicomTag>(c);
    }

// ------------------------ CANONICAL METHODS ------------------------

    @Override
    public boolean equals(Object o)
    {
        if (this == o) return true;
        if (!(o instanceof DicomTagList)) return false;

        DicomTagList that = (DicomTagList) o;

        return !(list != null ? !list.equals(that.list) : that.list != null);
    }

    @Override
    public int hashCode()
    {
        return list != null ? list.hashCode() : 0;
    }

// ------------------------ INTERFACE METHODS ------------------------


// --------------------- Interface Iterable ---------------------

    public Iterator<DicomTag> iterator()
    {
        return list.iterator();
    }

// -------------------------- OTHER METHODS --------------------------

    public void add(final DicomTag dicomTag)
    {
        list.add(dicomTag);
    }

    public void addAll(final Collection<? extends DicomTag> c)
    {
        list.addAll(c);
    }

    public void addAll(int index, final Collection<? extends DicomTag> c)
    {
        list.addAll(index, c);
    }

    public void clear()
    {
        list.clear();
    }

    public DicomTag get(int index)
    {
        return list.get(index);
    }

    public int indexOf(DicomTag dicomTag)
    {
        return list.indexOf(dicomTag);
    }

    public boolean isEmpty()
    {
        return list.isEmpty();
    }

    public boolean remove(DicomTag dicomTag)
    {
        return list.remove(dicomTag);
    }

    public DicomTag remove(int index)
    {
        return list.remove(index);
    }

    public boolean removeAll(final Collection<? extends DicomTag> c)
    {
        return list.removeAll(c);
    }

    /**
     * Replace the element at index, with a new element
     *
     * @param index    position at which the new element needs to be stored
     * @param dicomTag the new element that needs to be stored
     * @return The previous element stored at the index position
     */
    public DicomTag set(int index, DicomTag dicomTag)
    {
        return list.set(index, dicomTag);
    }

    public int size()
    {
        return list.size();
    }

    public Object[] toArray()
    {
        return list.toArray();
    }
}
